package mydubbo

import (
	mylogger "core/logger"
	"dubbo.apache.org/dubbo-go/v3/config"
	"github.com/dubbogo/gost/log/logger"
	"github.com/spf13/viper"
	"os"
)
import (
	_ "iotall/iotdeal/pkg"
)

var (
	DubboViper *viper.Viper
)

func Init() {

	var configFile = "./conf/dubbogo.yaml"
	_, err := os.Stat(configFile)
	if err != nil {
		configFile = "D:\\GoPath\\src\\communication-agent\\iotall\\iotdeal\\conf\\dubbogo.yaml"

		_, err := os.Stat(configFile)
		if err != nil {
			logger.Info(" 配置文件不存在")
			os.Exit(0)
		}
	}

	DubboViper = viper.New()
	DubboViper.SetConfigFile(configFile)
	DubboViper.ReadInConfig()

	if err := config.Load(config.WithPath(configFile)); err != nil {
		panic(err)
	}

	logger.SetLogger(mylogger.SugaredLogger)
}
